<!--#include virtual="/public/inc/head_inner.html"-->
<!--登录检查-->
<script type="text/javascript">
    (function () {

        //没有console的浏览器,添加空方法
        var noop=function(){};
        var custom_console={
            info:noop,
            warn:noop,
            error:noop
        };
        if (typeof console === "undefined"){
            window.console=custom_console;
        }

        // 获取用户信息url
        var callbackName = 'loginCallback';

        function getWindow(){
            var wind = window;

            try {
                while (wind.parent !== wind) {
                    wind = wind.parent;
                }
            } catch (e) {
            }

            return wind;
        }

        var goToLoginPage = function (url) {
            url = url || location.href;

            url = "/login.shtml?ret_url=" + encodeURIComponent(url);

            try {
                top.location.href = url;
            } catch (e) {
                var wind = getWindow();
                wind.location.href = url;
            }
        };

        window[callbackName] = function (json) {
            var userData = window['YKLoginData'] = json;
            if (userData) {
                var retCode = userData['retCode'];
                if (retCode == 0) {
                    var data = userData['data'];

                    if (data['isGuest'] !== false) {
                        goToLoginPage();
                    }
                } else if (retCode == '-1168202') {
                    location.href = '/';
                } else {
                    goToLoginPage();
                }
            }
        };

        function getUserInfoUrl() {
            function getUrlPara(name) {
                var search = location.search;
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = search.match(reg);
                if (r != null) {
                    return decodeURIComponent(r[2]);
                }
            }

            var url = '/api/index.php?r=site/login-data&callback=' + callbackName + '&t=' + new Date().getTime();

            var token = getUrlPara('token');
            if (token) {
                url += '&token=' + token;
            }
            return url;
        }

        document.open();
        document.write('<script type="text/javascript" src="' + getUserInfoUrl() + '"><\/script>');
        document.close();
    })();
</script>